<!-- 动态页面 -->
<template>
	<view>
		<post v-for="(item,index) in contList" 
		:key="item.id"
		:postDate="item"></post>
		
		<view>
			<uni-fab :pattern="pattern" :content="content"  @trigger="trigger"></uni-fab>
		</view>
	</view>
</template>

<script>
	import {onShow} from "@dcloudio/uni-app"
	export default {
		data() {
			return {
				contList: [],
				pattern: {
					color: '#7A7E83',
					backgroundColor: '#fff',
					selectedColor: '#007AFF',
					buttonColor: '#28B389',
					iconColor: '#fff'
				},
				content: [{
						id: 1,
						iconPath: '/static/images/postImage/like.png',
						selectedIconPath: '/static/images/postImage/yesLike.png',
						text: '喜欢',
						active: false
					},
					{
						id: 2,
						iconPath: '/static/images/postImage/show.png',
						selectedIconPath: '/static/images/postImage/show.png',
						text: '发布',
						active: false
					},
					{
						id: 3,
						iconPath: '/static/images/postImage/cangno.png',
						selectedIconPath: '/static/images/postImage/cang.png',
						text: '收藏',
						active: false
					}
				]
			};
		},
		onShow() { // 使用 onLoad 生命周期（或 onMounted 根据框架版本）
			this.loadContentData();
		},
		methods: {
			trigger(e) {
				console.log(e)
				if (e.index == 0) {
					this.content[2].active = false
					this.content[e.index].active = !e.item.active

					// 跳转我的喜欢
					console.log("我的喜欢")
				}
				if (e.index == 1) {
					uni.navigateTo({
						url: '/pages/onePost/onePost' // 带参数示例
					})
				}
				if (e.index == 2) {
					this.content[0].active = false
					this.content[e.index].active = !e.item.active

					// 跳转我的收藏
					console.log("我的收藏")
				}
			},
			loadContentData() {
				console.log("页面初始化")
				uni.request({
					url: "http://localhost:8081/sysDynamics/list",
					method: 'POST',
					data: {
						"pageSize": 10,
						"currentPage": 1
					},
					header: {
						'Authorization': 'Bearer ' + uni.getStorageSync('token') // 从本地存储获取token
					},
				}).then((res) => {
					if (res.data.code === '200') {
						console.log("结果为", res)
						this.contList = res.data.result
					} else {
						uni.showToast({
							title: res.data.message || '获取帖子失败',
							icon: 'none'
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss">

</style>